<template></template>

<script>
import {
  getnewdata,
  deletnewdata,
  updatenewdata,
  addenewdata,
} from "@/api/new.js";
export default {
  data() {
    return {
      newdata: [],
      page: 1, //分页器当前第几页
      limit: 5, //每一页需要展示几条数据
      total: 0,
      somedata: [],
      nowitem: {},
      dialogTableVisible: false,
      drawer: false,
      form: {},
      dialogImageUrl: "",
      dialogVisible: false,
      flag: 0, //0更新 1添加
    };
  },
  mounted() {
    this.initdata();
  },

  methods: {
    async initdata() {
      let result = await getnewdata();
      console.log(result);
      for (let i = 0; i < result.data.length; i++) {
        // 在循环中对数组中的元素进行操作
        result.data[i].like = JSON.parse(result.data[i].like); // 这里的 modifyElement 是你对元素进行修改的函数
        for (let j = 0; j < result.data[i].like.length; j++) {
          result.data[i].savergelike += result.data[i].like[j].value;
        }
        result.data[i].savergelike =
          result.data[i].savergelike / result.data[i].like.length;
      }

      if (result.status == 0) {
        this.newdata = result.data;
        this.total = this.newdata.length;
        this.somedata = this.newdata.slice(
          (this.page - 1) * this.limit,
          (this.page - 1) * this.limit + this.limit
        );
        this.$store.dispatch("news/savedata", this.newdata);
      }
    },
  },
};
</script>

<style>
</style>